/*
 * @Author: szx
 * @Date: 2022-03-02 15:10:46
 * @LastEditTime: 2022-03-02 15:18:33
 * @Description:
 * @FilePath: \leetcode\100-199\102\102_2.js
 */
/**
 * @param {TreeNode} root
 * @return {number[][]}
 */
var levelOrder = function (root) {
    if (!root) return [];
    const res = [];
    let que = [root];
    while (que.length) {
        const tmp = [];
        const tmp_que = [];
        for (let i = 0; i < que.length; i++) {
            tmp.push(que[i].val);
            if (que[i].left) tmp_que.push(que[i].left);
            if (que[i].right) tmp_que.push(que[i].right);
        }
        que = tmp_que;
        res.push(Array.from(tmp));
    }
    return res;
};
